const router = require('koa-router')()
const AppService = require("../service/appservice");
const redis = require("../config/redis");

router.get('/', async (ctx, next) => {
    await ctx.render('index', {
        title: 'Hello Koa 2!', name:1232
    })
})

router.get('/string', async (ctx, next) => {
    ctx.body = 'koa2 string'
})

router.get('/json', async (ctx, next) => {
    ctx.body = {
        title: 'koa2 json'
    }
})

router.get('/test', async (ctx, next) => {

    var list = await AppService.list();

    var rs = await redis.set('koa2', 'ddddddd');
    rs = await redis.get('koa2');
    //console.log(rs);

    ctx.body = JSON.stringify(list);
})

router.get('/test/ejs', async (ctx, next) => {
    // ctx.body = "fdsfds";
    await ctx.render('index', {name : '12222'});
})

module.exports = router
